package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.SmsFlashPromotionSessionMapper;
import com.mall.pojo.SmsFlashPromotionSession;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsFlashPromotionSessionApiImpl implements SmsFlashPromotionSessionApi{

    @Autowired
    private SmsFlashPromotionSessionMapper sessionMapper;

    /**
     * 获取所有秒杀时间段
     * @return
     */
    @Override
    public List<SmsFlashPromotionSession> list() {
        LambdaQueryWrapper<SmsFlashPromotionSession> wrapper = new LambdaQueryWrapper<>();
        return sessionMapper.selectList(wrapper);
    }

    /**
     * 添加秒杀活动场次
     * @param promotionSession
     */
    @Override
    public Integer create(SmsFlashPromotionSession promotionSession) {
        Integer count = sessionMapper.insert(promotionSession);
        return count;
    }

    /**
     * 根据id删除秒杀场次
     * @param id
     * @return
     */
    @Override
    public Integer delete(Integer id) {
        Integer count = sessionMapper.deleteById(id);
        return count;
    }

    /**
     * 修改秒杀场次
     * @param promotionSession
     * @return
     */
    @Override
    public Integer update(SmsFlashPromotionSession promotionSession) {
        Integer count = sessionMapper.updateById(promotionSession);
        return count;
    }

    /**
     * 根据id查询秒杀场次信息
     * @param id
     * @return
     */
    @Override
    public SmsFlashPromotionSession findById(Integer id) {
        return sessionMapper.selectById(id);
    }

    /**
     * 获取全部处于启用状态的秒杀场次
     * @param i
     * @return
     */
    @Override
    public List<SmsFlashPromotionSession> findByStatus(int i) {
        LambdaQueryWrapper<SmsFlashPromotionSession> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SmsFlashPromotionSession::getStatus,i);
        return sessionMapper.selectList(wrapper);
    }
}
